package de.andreavicentini.teatralia.pages.members;

import org.magiclabs.htmlx.HTMLString;
import org.magiclabs.htmlx.TextStructure;
import org.magiclabs.htmlx.TextStructure.TextKey;

import de.andreavicentini.teatralia.pages.Person;
import de.andreavicentini.teatralia.pages.Tokens;

public class Member extends Person implements Comparable<Member> {
	
	public enum Role implements TextStructure.TextKey {
		regista, attore, luci, fotografo;
	}
	
	private final TextKey id;
	public Member(
			TextStructure.TextKey id, 
			String firstName, String lastName,
			Sex sex,
			Role role,
			String city,
			Nationality nationality) {
		super(firstName, lastName, sex, city, nationality);
		
		this.id = id;
		this.role = role;
		this.image = id.toString();
		this.mail = createMailAddres(firstName, lastName);
	}

	private String createMailAddres(String firstName, String lastName) {
		//TODO ßöäü...
		return firstName.toLowerCase() + '.' + lastName + "@teatralia.de";
	}

	private final String image;
	public String getImage() { return image; }

	private final String mail;
	public String getMail() { return mail; }

	public TextKey getDescription() {
		return this.id;
	}
	
	private final Role role;
	public HTMLString getRole() {
		return Tokens.get(this.role.name(), this.sex);
	}
	
	public int compareTo(Member o) {
		int result = this.role.compareTo(o.role);
		if (result != 0) return result;
		return this.lastName.compareTo(o.getLastName());
	}
}
